package org.transaction.test.global_transaction.mybatis.utils;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;


/**
 * 获取sqlSession
 */
@Component
public class SqlContext {

    @Autowired
    @Qualifier("sqlSessionFactory1")
    private SqlSessionFactory sqlSessionFactory1;

    @Autowired
    @Qualifier("sqlSessionFactory2")
    private SqlSessionFactory sqlSessionFactory2;

    public SqlSession getSqlSession1(){
        SqlSessionFactory sqlSessionFactory = sqlSessionFactory1;
        return sqlSessionFactory.openSession();
    }

    public SqlSession getSqlSession2(){
        SqlSessionFactory sqlSessionFactory = sqlSessionFactory2;
        return sqlSessionFactory.openSession();
    }
}